package com.learn.base.model;

import com.learn.base.enums.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author : Yu.Tan
 * @date : 2023/1/17 18:03
 * @desc : **
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseResponse<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public static <T> BaseResponse<T> success() {
        BaseResponse result = new BaseResponse();
        result.setCode(ResultCode.SUCCESS.getCode());
        return result;
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    public static <T> BaseResponse<T> failure(ResultCode resultCode) {
        return new BaseResponse(resultCode.getCode(), resultCode.getMessage(), null);
    }

    public static <T> BaseResponse<T> failure(ResultCode resultCode, T data) {
        return new BaseResponse(resultCode.getCode(), resultCode.getMessage(), data);
    }
}
